package com.peaker.advertisingpro.utils

import android.content.Context
import android.content.SharedPreferences
import android.text.TextUtils

/**
 *  @ 作者 CODE_LYF
 *  @ 时间   2021/4/5.
 *  代码人生
 */
object SPUtil{

    val mTAG = "advertsp"
    private lateinit var mPreferences: SharedPreferences
    private lateinit var mEditor: SharedPreferences.Editor



    fun initSpUtils(context: Context){
        mPreferences = context.getSharedPreferences(mTAG, Context.MODE_PRIVATE)
        mEditor = mPreferences.edit()
    }


    // 存入数据
    fun putSP(key: String, value: String) {
        if(TextUtils.isEmpty(value)){
            return
        }
        mEditor.putString(key, value)
        mEditor.commit()

    }

    // 获取数据
    fun getSP(key: String): String? {
        return mPreferences.getString(key, "")
    }
    fun getSP(key: String,default:String): String? {
        return mPreferences.getString(key, default)
    }
    // 移除数据
    fun removeSP(key: String) {
        mEditor.remove(key)
        mEditor.commit()
    }

    fun removeAll() {
        mEditor.clear()
        mEditor.commit()
    }


}